/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * JanelaRevogarLei.java
 *
 * Created on 03/04/2011, 17:32:57
 */
package gui;

import java.util.List;
import javax.swing.JOptionPane;
import modelo.Lei;

/**
 *
 * @author Jackson
 */
public class JanelaRevogarLei extends javax.swing.JFrame implements UI {

    /** Creates new form JanelaRevogarLei */
    public JanelaRevogarLei() {
        initComponents();
        setLocationRelativeTo(null);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        labelLeiRevoga = new javax.swing.JLabel();
        labelLeiRevogada = new javax.swing.JLabel();
        campoLeiRevoga = new javax.swing.JTextField();
        campoLeiRevogada = new javax.swing.JTextField();
        botaoPesquisar = new javax.swing.JButton();
        botaoCancelar = new javax.swing.JButton();
        botaoRevogar = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Revogar Leis");
        setResizable(false);

        labelLeiRevoga.setText("Numero Lei Revoga:");

        labelLeiRevogada.setText("Numero Lei Revogada:");

        botaoPesquisar.setText("Pesquisar");
        botaoPesquisar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botaoPesquisarActionPerformed(evt);
            }
        });

        botaoCancelar.setText("Limpar");
        botaoCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botaoCancelarActionPerformed(evt);
            }
        });

        botaoRevogar.setText("Revogar");
        botaoRevogar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botaoRevogarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(22, 22, 22)
                                .addComponent(labelLeiRevoga))
                            .addGroup(layout.createSequentialGroup()
                                .addContainerGap()
                                .addComponent(labelLeiRevogada)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(campoLeiRevoga, javax.swing.GroupLayout.DEFAULT_SIZE, 389, Short.MAX_VALUE)
                            .addComponent(campoLeiRevogada, javax.swing.GroupLayout.DEFAULT_SIZE, 389, Short.MAX_VALUE)))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addContainerGap(269, Short.MAX_VALUE)
                        .addComponent(botaoPesquisar)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(botaoCancelar)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(botaoRevogar)))
                .addContainerGap())
        );

        layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {botaoCancelar, botaoPesquisar, botaoRevogar});

        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(labelLeiRevoga)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(campoLeiRevoga, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(8, 8, 8)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(campoLeiRevogada, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(labelLeiRevogada))))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(botaoPesquisar)
                    .addComponent(botaoCancelar)
                    .addComponent(botaoRevogar))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void botaoPesquisarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botaoPesquisarActionPerformed
        janelaPesquisarLei.setVisible(true);
    }//GEN-LAST:event_botaoPesquisarActionPerformed

    private void botaoCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botaoCancelarActionPerformed
        campoLeiRevoga.setText(null);
        campoLeiRevogada.setText(null);
    }//GEN-LAST:event_botaoCancelarActionPerformed

    private void botaoRevogarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botaoRevogarActionPerformed
            Lei revoga = new Lei();
            Lei revogada = new Lei();
            revoga.setNumeroLei(campoLeiRevoga.getText());
            revogada.setNumeroLei(campoLeiRevogada.getText());

        if (campoLeiRevoga.getText() == null || campoLeiRevogada.getText() == null) {
            exibirMensagemErro("Campo Nulo encontrado");
        } else if(controladorRevogarLei.existObject(revoga) && controladorRevogarLei.existObject(revogada)){
            controladorRevogarLei.revogar(revoga, revogada);
            exibirMensagem("Revogada Com Sucesso");
            limparTela();
        }else{
                exibirMensagemErro("Lei não existente");
        }

    }//GEN-LAST:event_botaoRevogarActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton botaoCancelar;
    private javax.swing.JButton botaoPesquisar;
    private javax.swing.JButton botaoRevogar;
    private javax.swing.JTextField campoLeiRevoga;
    private javax.swing.JTextField campoLeiRevogada;
    private javax.swing.JLabel labelLeiRevoga;
    private javax.swing.JLabel labelLeiRevogada;
    // End of variables declaration//GEN-END:variables
    private ControladorRevogarLei controladorRevogarLei;
    private JanelaPesquisarLei janelaPesquisarLei;

    public JanelaPesquisarLei getJanelaPesquisarLei() {
        return janelaPesquisarLei;
    }

    public void setJanelaPesquisarLei(JanelaPesquisarLei janelaPesquisarLei) {
        this.janelaPesquisarLei = janelaPesquisarLei;
    }

    public ControladorRevogarLei getControladorRevogarLei() {
        return controladorRevogarLei;
    }

    public void setControladorRevogarLei(ControladorRevogarLei controladorRevogarLei) {
        this.controladorRevogarLei = controladorRevogarLei;
    }

    public Controlador getControlador() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public void setControlador(Controlador c) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public void exibirMensagem(String mensagem) {
        JOptionPane.showMessageDialog(this, mensagem);
    }

    public void exibirMensagemErro(String mensagem) {
        JOptionPane.showMessageDialog(this, mensagem, "Erro!", JOptionPane.ERROR_MESSAGE);
    }

    public void mostrarObjeto(Object o) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public void mostrarObjetos(List l) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public void limparTela() {
        campoLeiRevoga.setText(null);
        campoLeiRevogada.setText(null);
    }
}
